#define _CRT_SECURE_NO_WARNINGS

#include"c1.h"

//typedef struct
//{
//	char *base;
//	int front;
//	int rear;
//}SqQueue;
//Status InitQueue(SqQueue *Q);
//Status EnQueue(SqQueue *Q,char e);
//Status DeQueue(SqQueue *Q,char *e);
//int QueueLength(SqQueue Q);


Status InitQueue(SqQueue* Q)
{
	Q->base = (char*)malloc(MAXQSIZE * sizeof(char));
	if (!Q->base)
		OVERFLOW;
	Q->front = Q->rear = 0;
	return OK;
}
Status EnQueue(SqQueue* Q, char e)
{
	if ((Q->rear + 1) % MAXQSIZE == Q->front)
		return ERROR;
	Q->base[Q->rear] = e;
	Q->rear = (Q->rear + 1) % MAXQSIZE;
	return OK;
}
Status DeQueue(SqQueue* Q, char* e)
{
	if (Q->front == Q->rear)
		return ERROR;
	*e = Q->base[Q->front];
	Q->front = (Q->front + 1) % MAXQSIZE;
	return OK;
}
int QueueLength(SqQueue Q)
{
	return (Q.rear - Q.front + MAXQSIZE) % MAXQSIZE;
}



